<template>
    <a-card :bordered="false">
        <s-table
            ref="table"
            :columns="columns"
            :data="loadData"
            :alert="options.alert.show"
            bordered
            :row-key="(record) => record.wfSendRoundInfoId"
            :tool-config="toolConfig"
            :row-selection="options.rowSelection"
        >
            <template #operator class="table-operator">
                <a-space>
                    <a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('flwSendRoundInfoAdd')">
                        <template #icon><plus-outlined /></template>
                        新增
                    </a-button>
                    <a-button danger @click="deleteBatchFlwSendRoundInfo()" v-if="hasPerm('flwSendRoundInfoBatchDelete')">删除</a-button>
                </a-space>
            </template>
            <template #bodyCell="{ column, record }">
                <template v-if="column.dataIndex === 'action'">
                    <a-space>
                        <a @click="formRef.onOpen(record)" v-if="hasPerm('flwSendRoundInfoEdit')">编辑</a>
                        <a-divider type="vertical" v-if="hasPerm(['flwSendRoundInfoEdit', 'flwSendRoundInfoDelete'], 'and')" />
                        <a-popconfirm title="确定要删除吗？" @confirm="deleteFlwSendRoundInfo(record)">
                            <a-button type="link" danger size="small" v-if="hasPerm('flwSendRoundInfoDelete')">删除</a-button>
                        </a-popconfirm>
                    </a-space>
                </template>
            </template>
        </s-table>
    </a-card>
    <Form ref="formRef" @successful="table.refresh(true)" />
</template>

<script setup name="flwsendroundinfo">
    import { message } from 'ant-design-vue'
    import Form from './form.vue'
    import flwSendRoundInfoApi from '@/api/biz/flwSendRoundInfoApi'
    const table = ref()
    const formRef = ref()
    const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
    const columns = [
        {
            title: 'WORKFLOW_MESSAGES_ID',
            dataIndex: 'workflowMessagesId'
        },
        {
            title: 'MESSAGE_WORKITEM_ID',
            dataIndex: 'messageWorkitemId'
        },
        {
            title: 'MESSAGE_TRACK_ID',
            dataIndex: 'messageTrackId'
        },
        {
            title: 'PROCESS_INSTANCE_ID',
            dataIndex: 'processInstanceId'
        },
        {
            title: 'PRO_FORM_NO',
            dataIndex: 'proFormNo'
        },
        {
            title: 'PRO_FORM_NAME',
            dataIndex: 'proFormName'
        },
        {
            title: 'WF_SECTION_ID',
            dataIndex: 'wfSectionId'
        },
        {
            title: 'WF_SECTION_NAME',
            dataIndex: 'wfSectionName'
        },
        {
            title: 'WF_MESSAGE_TYPE',
            dataIndex: 'wfMessageType'
        },
        {
            title: 'DJ_AUDIT_STATUS',
            dataIndex: 'djAuditStatus'
        },
        {
            title: 'DATE_PRIMARYKEY_ID',
            dataIndex: 'datePrimarykeyId'
        },
        {
            title: 'SEND_PERSON_PARTYID',
            dataIndex: 'sendPersonPartyid'
        },
        {
            title: 'SEND_PERSON_CODE',
            dataIndex: 'sendPersonCode'
        },
        {
            title: 'SEND_PERSON_NAME',
            dataIndex: 'sendPersonName'
        },
        {
            title: 'RECEIVE_PERSON_PARTYID',
            dataIndex: 'receivePersonPartyid'
        },
        {
            title: 'RECEIVE_PERSON_CODE',
            dataIndex: 'receivePersonCode'
        },
        {
            title: 'RECEIVE_PERSON_NAME',
            dataIndex: 'receivePersonName'
        },
        {
            title: 'READ_STATE',
            dataIndex: 'readState'
        },
        {
            title: 'READ_TIME',
            dataIndex: 'readTime'
        },
        {
            title: 'SEND_TIME',
            dataIndex: 'sendTime'
        },
        {
            title: 'RECEIVE_PERSON_DEPT_CODE',
            dataIndex: 'receivePersonDeptCode'
        },
        {
            title: 'RECEIVE_PERSON_DEPT_ID',
            dataIndex: 'receivePersonDeptId'
        },
        {
            title: 'RECEIVE_PERSON_DEPT_NAME',
            dataIndex: 'receivePersonDeptName'
        },
        {
            title: 'RECEIVE_PERSON_COMPANY_CODE',
            dataIndex: 'receivePersonCompanyCode'
        },
        {
            title: 'RECEIVE_PERSON_COMPANY_ID',
            dataIndex: 'receivePersonCompanyId'
        },
        {
            title: 'RECEIVE_PERSON_COMPANY_NAME',
            dataIndex: 'receivePersonCompanyName'
        },
        {
            title: 'SEND_MARK',
            dataIndex: 'sendMark'
        },
        {
            title: 'SYS_PARTY_CODE',
            dataIndex: 'sysPartyCode'
        },
        {
            title: 'USABLE_STATUS',
            dataIndex: 'usableStatus'
        },
        {
            title: 'CREATE_DATE',
            dataIndex: 'createDate'
        },
        {
            title: 'CREATE_IP',
            dataIndex: 'createIp'
        },
        {
            title: 'CREATE_USER_ID',
            dataIndex: 'createUserId'
        },
        {
            title: 'MODIFY_DATE',
            dataIndex: 'modifyDate'
        },
        {
            title: 'MODIFY_IP',
            dataIndex: 'modifyIp'
        },
        {
            title: 'MODIFY_USER_ID',
            dataIndex: 'modifyUserId'
        },
        {
            title: 'ORDER_CODE',
            dataIndex: 'orderCode'
        },
        {
            title: 'ATTRIBUTE1',
            dataIndex: 'attribute1'
        },
        {
            title: 'ATTRIBUTE2',
            dataIndex: 'attribute2'
        },
        {
            title: 'ATTRIBUTE3',
            dataIndex: 'attribute3'
        },
        {
            title: 'ATTRIBUTE4',
            dataIndex: 'attribute4'
        },
        {
            title: 'ATTRIBUTE5',
            dataIndex: 'attribute5'
        },
        {
            title: 'RECEIVE_PERSON_CUMAIL',
            dataIndex: 'receivePersonCumail'
        },
        {
            title: 'RECEIVE_PERSON_OU',
            dataIndex: 'receivePersonOu'
        },
        {
            title: 'SEND_PERSON_CUMAIL',
            dataIndex: 'sendPersonCumail'
        },
        {
            title: 'SEND_PERSON_OU',
            dataIndex: 'sendPersonOu'
        },
        {
            title: 'WORKFLOW_NAME',
            dataIndex: 'workflowName'
        },
    ]
    // 操作栏通过权限判断是否显示
    if (hasPerm(['flwSendRoundInfoEdit', 'flwSendRoundInfoDelete'])) {
        columns.push({
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            width: '150px'
        })
    }
    let selectedRowKeys = ref([])
    // 列表选择配置
    const options = {
        alert: {
            show: false,
            clear: () => {
                selectedRowKeys = ref([])
            }
        },
        rowSelection: {
            onChange: (selectedRowKey, selectedRows) => {
                selectedRowKeys.value = selectedRowKey
            }
        }
    }
    const loadData = (parameter) => {
        return flwSendRoundInfoApi.flwSendRoundInfoPage(parameter).then((data) => {
            return data
        })
    }
    // 删除
    const deleteFlwSendRoundInfo = (record) => {
        let params = [
            {
                wfSendRoundInfoId: record.wfSendRoundInfoId
            }
        ]
        flwSendRoundInfoApi.flwSendRoundInfoDelete(params).then(() => {
            table.value.refresh(true)
        })
    }
    // 批量删除
    const deleteBatchFlwSendRoundInfo = () => {
        if (selectedRowKeys.value.length < 1) {
            message.warning('请选择一条或多条数据')
            return false
        }
        const params = selectedRowKeys.value.map((m) => {
            return {
                wfSendRoundInfoId: m
            }
        })
        flwSendRoundInfoApi.flwSendRoundInfoDelete(params).then(() => {
            table.value.clearRefreshSelected()
        })
    }
</script>
